/**
 *  Java Api For Ecco Generated Applications
 *
 *  Copyright (C) 2000  by PDTec GmbH
 *
 * @author  Michael Weirich
 */

package pdtec.ecco.inst;

import pdtec.ecco.meta.Type;
import pdtec.ecco.meta.Attribute;
import pdtec.ecco.meta.EccoException;
import pdtec.ecco.meta.Application;


/**
 * Objects of class Instance represent EXPRESS entity instances.
 *
 * @see  pdtec.ecco.inst.Value
 * @see  pdtec.ecco.inst.AggregateValue
 */
public class Instance extends Value {


    /** This constructor enables instance creation by type. */
    public Instance(Type type) {
	super(type);
    } // constructor

    /** This constructor is protected since instance creation is delegated to  the static
     * {@link pdtec.ecco.inst.Value#get(int,long) get(..) } method.
     */
    protected Instance(int appId, long id) {
	super(appId,id);
    } // constructor

    /** Same as EXPRESS built in function USEDIN. 
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized Instance[] usedIn(String role) throws EccoException;

    /** Same as EXPRESS built in function ROLESOF.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized String[] rolesOf() throws EccoException;

    /** Instance access by attribute.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized Value attr(Attribute attr) throws EccoException;

    /** Instance access by identifier.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized Value attr(String attr) throws EccoException;

    /** Instance access by group and name.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized Value attr(String group, String attr) throws EccoException;

    /** Assignment by attribute.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized void  putAttr(Attribute attr, Value val) throws EccoException;

    /** Assignment by identifier.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized void putAttr(String attr, Value val) throws EccoException;

    /** Assignment by identifier.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public void putAttr(String attr, String value) throws EccoException {
	putAttr(attr,new Value(value,Type.getByName(appId,"","STRING")));
    } // putAttr

    /** Assignment by identifier.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public void putAttr(String attr, int value) throws EccoException {
	putAttr(attr,new Value((long) value,Type.getByName(appId,"","INTEGER")));
    } // putAttr

    /** Assignment by identifier.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public void putAttr(String attr, long value) throws EccoException {
	putAttr(attr,new Value(value,Type.getByName(appId,"","INTEGER")));
    } // putAttr

    /** Assignment by identifier.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public void putAttr(String attr, double value) throws EccoException {
	putAttr(attr,new Value(value,Type.getByName(appId,"","REAL")));
    } // putAttr

    /** Assignment by identifier.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public void putAttr(String attr, boolean value) throws EccoException {
	putAttr(attr,new Value(value,Type.getByName(appId,"","BOOLEAN")));
    } // putAttr

    /** Assignment by group and identifier.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized void  putAttr(String group, String attr,
					     Value val) throws EccoException;

    /** Make this object persistent.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized void create() throws EccoException;

    /** Make this object impersistent.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized void destroy() throws EccoException;

    /** Returns persistent property status.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized boolean persistent() throws EccoException;

    /** Type extension at run time.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized void extend(Type tp) throws EccoException;

    /** Cancels previously defined type extension.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native synchronized void drop(Type tp) throws EccoException;

    /** Returns ecco application generated object ids. Note: this is
     * not the Value.id.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
     public native synchronized String getOid() throws EccoException;

    /** Returns instance with specified object id and application context.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs */
    static public native synchronized Instance getByOid(int appId,String oid) throws EccoException;

    /** Operation call.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native Value operation(String name, Value[] params) throws EccoException;

    /** Operation call.
     * @exception pdtec.ecco.inst.EccoException in case an error occurs
     */
    public native Value operation(String group, String name,
				  Value[] params) throws EccoException;

    /** Finalizes objects of class Instance. */
    protected void finalize() {
	super.finalize();
    } // finalize

} // class Instance











